#include <iostream>
#include <string>
#include "tcpserver.h"

int main(int argc, char const *argv[])
{
    // 设置默认端口
    int port = 5566;
    if (argc > 1) {
        std::string portStr = argv[1];
        try {
            port = std::stoi(portStr);
            if (port < 1 || port > 65535) {
                throw std::out_of_range("Port number out of range");
            }
        } catch (const std::invalid_argument& e) {
            std::cerr << "Invalid port argument: " << e.what() << std::endl;
            return 1;
        } catch (const std::out_of_range& e) {
            std::cerr << "Invalid port number: " << e.what() << std::endl;
            return 1;
        }
    }
    // 启动 TCP 服务器任务
    if (tcpserver_task(port) != 0) {
        std::cerr << "Failed to start TCP server task" << std::endl;
        return 1;
    }
    return 0;
}
